package com.yanqu.backendweb.validation.validators;

import com.yanqu.backendweb.utils.SpringContext;
import com.yanqu.backendweb.validation.constraints.Customizer;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author duli
 * @version 1.0
 * @date 2020/22/01 11:44
 * @Description
 */
public class CustomizerValidator implements ConstraintValidator<Customizer, Object> {

    private CustomizerValidService service;

    @Override
    public void initialize(Customizer constraintAnnotation) {
        service = SpringContext.getBean(constraintAnnotation.value());
    }

    @SuppressWarnings("unchecked")
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return service.isValid(value);
    }
}
